home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 179 / MF_UK_179_1.iso / DiscContents / In the mag / Widgets / PEMDAS 1.0 / PEMDAS / PEMDAS.wdgt / pemdasUpdater.js < prev   
Encoding:
Text File  |  2006-12-12  |  3.1 KB  |  108 lines

  1. var xmlRequest;
  2. function checkForUpdates()
  3. {
  4. var currentTime;
  5. if (!preferencesIgnoreUpdates) {
  6. currentTime=new Date();
  7. currentTime=parseFloat(currentTime.getTime())/1000;
  8. if ((currentTime-lastCheckedTime)>1800) {
  9. startXMLRequest();
  10. lastCheckedTime=new Date();
  11. lastCheckedTime=parseFloat(lastCheckedTime.getTime())/1000;
  12. }
  13. }
  14. }
  15. function startXMLRequest()
  16. {
  17. xmlRequest = new XMLHttpRequest();
  18. xmlRequest.onreadystatechange = finishXMLRequest; 
  19. xmlRequest.overrideMimeType("text/xml");
  20. xmlRequest.open("GET", "http://updates.donkeyentertainment.com/pemdas.php?r=R35");
  21. xmlRequest.send();
  22. }
  23. function finishXMLRequest()
  24. {
  25. if (xmlRequest.readyState == 4) {
  26. if (xmlRequest.status == 200) { 
  27. parseXMLData();
  28. } else { 
  29. }
  30. }    
  31. }
  32. function parseXMLData()
  33. {    
  34. var pemdasVersionData = findXMLChild(xmlRequest.responseXML, "pemdasVersionData");
  35. if (!pemdasVersionData) return;
  36. var currentVersionInfo = findXMLChild(pemdasVersionData, "currentVersionInfo");
  37. if (!currentVersionInfo) return;
  38. currentReleaseNumber=currentVersionInfo.version;
  39. currentReleaseMessage=currentVersionInfo.message;
  40. currentReleaseURL=currentVersionInfo.url;
  41. if (thisVersionNumber!=currentReleaseNumber) {
  42. displayVersionUpdateBox();
  43. }
  44. }
  45. function findXMLChild(element, nodeName)
  46. {
  47. var child;
  48. for (child = element.firstChild; child != null; child = child.nextSibling) {
  49. if (child.nodeName == nodeName)
  50. return child;
  51. }
  52. return false;
  53. }
  54. function displayVersionUpdateBox()
  55. {
  56. document.getElementById('updateMessage').innerHTML=currentReleaseMessage;
  57. document.getElementById('updateDontTell').innerHTML="Don't tell me about PEMDAS " + currentReleaseNumber +" again."
  58. document.getElementById('updateDivContainer').style.display='block';
  59. }
  60. function openUpdateURL()
  61. {
  62. if(window.widget)
  63. widget.openURL(currentReleaseURL);
  64. document.getElementById('updateDivContainer').style.display='none';
  65. }
  66. function turnUpdateButtonOn(updateButton)
  67. {
  68. document.getElementById('updateLeft'+updateButton).className='updateLeftOn';
  69. document.getElementById('updateMiddle'+updateButton).className='updateMiddleOn';
  70. document.getElementById('updateRight'+updateButton).className='updateRightOn';
  71. }
  72. function turnUpdateButtonOff(updateButton)
  73. {
  74. document.getElementById('updateLeft'+updateButton).className='updateLeftOff';
  75. document.getElementById('updateMiddle'+updateButton).className='updateMiddleOff';
  76. document.getElementById('updateRight'+updateButton).className='updateRightOff';
  77. }
  78. function turnCheckboxOn()
  79. {
  80. if (preferencesIgnoreUpdates) {
  81. document.getElementById('updateCheckbox').src="images/updateBox/checkboxOnDown.png";
  82. } else {
  83. document.getElementById('updateCheckbox').src="images/updateBox/checkboxOffDown.png";
  84. }
  85. }
  86. function turnCheckboxOff()
  87. {
  88. if (preferencesIgnoreUpdates) {
  89. document.getElementById('updateCheckbox').src="images/updateBox/checkboxOn.png";
  90. } else {
  91. document.getElementById('updateCheckbox').src="images/updateBox/checkboxOff.png";
  92. }
  93. }
  94. function toggleCheckbox()
  95. {
  96. preferencesIgnoreUpdates++;
  97. if (preferencesIgnoreUpdates>=2)
  98. preferencesIgnoreUpdates=0;
  99. turnCheckboxOff();
  100. if (window.widget) {
  101. widget.setPreferenceForKey(preferencesIgnoreUpdates,"preferencesIgnoreUpdates");
  102. }
  103. }
  104. function cancelUpdate()
  105. {
  106. document.getElementById('updateDivContainer').style.display='none';
  107. }
  108.